/*
 * All rights Reserved, Designed By Rylynn
 * @ClassName:  Vertex
 * @Description:
 * @author: rylynn
 * @date:   2021/7/7
 *
 */

package org.etnetwork.core;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class Vertex implements Serializable {
    final Long serialVersionUID = 1L;
    private Long vid;
    private Map<String, Object> properties;

    public Vertex(Long vid) {
        if (vid < 0) {
            throw new IllegalArgumentException(String.format("Vertex ID should be not less than 0, but get %d", vid));
        }
        this.vid = vid;
        this.properties = new HashMap<>();
    }
    public Vertex(Map<String, Object> properties) {
        this.properties = properties;
    }

    public Vertex(Long vid, Map<String, Object> properties) {
        this.vid = vid;
        this.properties = properties;
    }

    public Vertex() {
        this.vid = -1L;
        this.properties = new HashMap<>();
    }

    public Map<String, Object> getProperties() {
        return properties;
    }

    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
    }

    public void addProperties(String key, Object value) {
        this.properties.put(key, value);
    }

    public void updateProperties(String key, Object value) {
        this.addProperties(key, value);
    }

    public Long getVid() {
        return vid;
    }

    public void setVid(Long vid) {
        this.vid = vid;
    }

    @Override
    public boolean equals(Object o) {
        if (o.getClass() != Vertex.class) {
            return false;
        }
        Vertex obj = (Vertex) o;
        return obj.getVid().equals(this.getVid());
    }

}
